#include <stdio.h>
#include <stdlib.h>

typedef int ElementType;
typedef struct AVLNode* AVLTree;
struct AVLNode {
    ElementType Data;
    AVLTree Left;
    AVLTree Right;
    int H;
};
void free_tree ( AVLTree BT ) {
    if (BT) {
        AVLTree tmp = BT;
        free_tree(BT->Left);
        free(tmp);
        printf("free success\n");
        free_tree(BT->Right);
    }
}
int Max ( ElementType a, ElementType b ) {
    return a > b ? a : b;
}

int GetH ( AVLTree T );
AVLTree LL ( AVLTree A );
AVLTree RR ( AVLTree A );
AVLTree LR ( AVLTree A );
AVLTree RL ( AVLTree A );
AVLTree Insert ( AVLTree A, ElementType X );

int main () {
    int N, X, i;
    AVLTree A;
    scanf("%d",&N);
    for ( i = 0; i < N; i++ ) {
        scanf("%d",&X);
        A = Insert ( A, X );
    }
    printf("%d\n",A->Data);
    free_tree(A); 
    return 0;
}

int GetH ( AVLTree T ) {
    if (T) return T->H;
    else return -1;
}
AVLTree LL ( AVLTree A ) {
    AVLTree B = A->Left;
    A->Left = B->Right;
    B->Right = A;
    A->H = Max(GetH(A->Left), GetH(A->Right)) + 1;
    B->H = Max(GetH(B->Left), GetH(B->Right)) + 1;
    return B;
}
AVLTree RR ( AVLTree A ) {
    AVLTree B = A->Right;
    A->Right = B->Left;
    B->Left = A;
    A->H = Max( GetH(A->Left), GetH(A->Right) ) + 1;
    B->H = Max( GetH(B->Left), GetH(B->Right) ) + 1;
    return B;
}
AVLTree LR ( AVLTree A ) {
    A->Left = RR(A->Left);
    return LL(A);
}
AVLTree RL ( AVLTree A ) {
    A->Right = LL(A->Right);
    return RR(A);
}
AVLTree Insert ( AVLTree A, ElementType X ) {
    if ( !A ) {
        A = (AVLTree)malloc(sizeof(struct AVLNode));
        A->Data = X;
        A->Left = A->Right = NULL;
        A->H = 0;
    } else if ( X > A->Data ) {
        A->Right = Insert(A->Right,X);
        if ( GetH(A->Right) - GetH(A->Left) == 2 ) {
            if ( X < A->Right->Data ) A = RL(A);
            else A = RR(A);
        }
    } else if ( X < A->Data ) {
        A->Left = Insert(A->Left,X);
        if ( GetH(A->Left) - GetH(A->Right) == 2 ) {
            if ( X > A->Left->Data ) A = LR(A);
            else A = LL(A);
        }
    }
    A->H = Max(GetH(A->Left), GetH(A->Right))+1;
    return A;
}
